<div class="form-item clearfix">
	<div class="input-label"><if condition="($data eq NULL or $data['status'] eq -1) and $data['noedit'] neq 1"><span class="asterisk">*</span></if></if>代理人姓名</div>
	<div class="input-item">
		<if condition="$data['noedit'] neq 1">
			<if condition="$data neq NULL">
				<if condition="$data['status'] eq -1">
					<if condition="$data['agent_post'] neq NULL">
						<if condition="$users eq NULL">
							<select class="form-control select-add w150" name="agent2" autocomplete="off">
								<option value="-10">暂无相关人员</option>
							</select>
						<else/>
							<select class="form-control select-add w150" name="agent2" autocomplete="off">
								<option value="-10">请选择</option>
								<foreach name="users" item="vo">
									<option value="{$vo['id']}" z-name="{$vo['position']}" t-tell="{$vo['mobilephone']}">{$vo['username']}</option>
								</foreach>
							</select>
						</if>
						<input type="text" name="agent_name2" class="form-control w150 ml5 select-add-text" value="{$data['agent']}">
					<else/>
						<select class="form-control select-add w150" name="agent2" autocomplete="off">
							<option value="-10">请选择</option>
							<foreach name="users" item="vo">
								<option value="{$vo['id']}" z-name="{$vo['position']}" t-tell="{$vo['mobilephone']}" <if condition="$data['agent'] eq $vo['id']">selected</if>>{$vo['username']}</option>
							</foreach>
						</select>
						<input type="text" name="agent_name2" class="form-control w150 ml5 select-add-text hide">
						<span class="error-item">必填项</span>
					</if>
				<else/>
					<if condition="$data['agent_post'] eq NULL">{$data['agent_name']}<else/>{$data['agent']}</if>
				</if>
			<else/>
				<select class="form-control select-add w150" name="agent1" autocomplete="off">
					<option value="-10">请先选择项目</option>
				</select>
				<input type="text" name="agent_name1" class="form-control w150 ml5 select-add-text">
				<span class="error-item">必填项</span>
			</if>
		<else/>
			<if condition="$data['agent_post'] eq NULL">{$data['agent_name']}<else/>{$data['agent']}</if>
		</if>
	</div>
</div>
<div class="form-item clearfix">
	<div class="input-label"><if condition="($data eq NULL or $data['status'] eq -1) and $data['noedit'] neq 1"><span class="asterisk">*</span></if></if>代理人职务</div>
	<div class="input-item">
		<if condition="$data['noedit'] neq 1">
			<if condition="$data neq NULL">
				<if condition="$data['status'] eq -1">
					<if condition="$data['agent_post'] neq NULL">
						<input type="text" name="agent_post2" class="form-control w150" value="{$data['agent_post']}">
						<span class="hide txt"></span>
					<else/>
						<input type="text" name="agent_post2" class="form-control w150 hide">
						<span class="txt">{$data['position']}</span>
					</if>
				<else/>
					<if condition="$data['agent_post'] eq NULL">{$data['position']}<else/>{$data['agent_post']}</if>
				</if>
			<else/>
				<input type="text" name="agent_post1" class="form-control w150">
				<span class="hide txt"></span>
			</if>
			<span class="error-item">必填项</span>
		<else/>
			<if condition="$data['agent_post'] eq NULL">{$data['position']}<else/>{$data['agent_post']}</if>
		</if>
	</div>
</div>
<div class="form-item clearfix">
	<div class="input-label"><if condition="($data eq NULL or $data['status'] eq -1) and $data['noedit'] neq 1"><span class="asterisk">*</span></if></if>手机号</div>
	<div class="input-item">
		<if condition="$data['noedit'] neq 1">
			<if condition="$data neq NULL">
				<if condition="$data['status'] eq -1">
					<if condition="$data['agent_post'] neq NULL">
						<input type="text" name="agent_tel2" class="form-control w150" value="{$data['agent_tel']}">
						<span class="hide txt"></span>
					<else/>
						<input type="text" name="agent_tel2" class="form-control w150 hide">
						<span class="txt">{$data['mobilephone']}</span>
					</if>
				<else/>
					<if condition="$data['agent_post'] eq NULL">{$data['mobilephone']}<else/>{$data['agent_tel']}</if>
				</if>
			<else/>
				<input type="text" name="agent_tel1" class="form-control w150">
				<span class="hide txt"></span>
			</if>
			<span class="error-item">必填项</span>
		<else/>
			<if condition="$data['agent_post'] eq NULL">{$data['mobilephone']}<else/>{$data['agent_tel']}</if>
		</if>
	</div>
</div>
<if condition="$data['status'] egt 1">
<div class="form-item clearfix">
	<foreach name="audit_user" item="vo">
	<div class="input-label"><if condition="$key eq 0">审核流程</if></div>
	<div class="input-item">
		{$vo['audit_name']}:
			<if condition="$vo['audit_date'] neq NULL">
				{$vo['audit_user']}({$vo['audit_date']|substr=0,10})<if condition="$vo['audit_comments'] neq NULL">批复:{$vo['audit_comments']}</if><if condition="$vo['dh_message'] neq NULL"><br/><span>打回至"{$vo['arrive_name']}"({$vo['dh_date']|substr=0,10})原因:{$vo['dh_message']}</span></if><if condition="$vo['arrive_info'] neq NULL"><br/><span>"{$vo['arrive_name']}"({$vo['arrive_date']|substr=0,10})回复:{$vo['arrive_info']}</span></if>
			<else/>
				<span class='red'>[未审核]{$vo['audit_user']}</span><if condition="$vo['dh_message'] neq NULL"><br/><span class='red'>打回至"{$vo['arrive_name']}"({$vo['dh_date']|substr=0,10})原因:{$vo['dh_message']}</span></if><if condition="$vo['arrive_info'] neq NULL"><br/><span class='red'>"{$vo['arrive_name']}"({$vo['arrive_date']|substr=0,10})回复:{$vo['arrive_info']}</span></if>
			</if>
	</div>
	</foreach>
</div>
</if>
<if condition="$data['dh_message'] neq '' and $data['status'] eq -1">
<div class="form-item clearfix">
	<div class="input-label">打回原因</div>
	<div class="input-item">
		<span class="red">{$data['dh_user']}({$data['dh_date']|substr=0,10}):{$data['dh_message']}</span>
	</div>
</div>
</if>
<!--<if condition="$data['submit_info'] neq ''">
<div class="form-item clearfix">
	<div class="input-label">重新提交理由</div>
	<div class="input-item">
		<span class="red">{$data['submit_user']}:{$data['submit_info']}</span>
	</div>
</div>-->
</if>
<div class="load_foot">
	<if condition="$data['noedit'] neq 1">
		<if condition="$data['id'] neq NULL">
			<if condition="$data['status'] eq -1">
				<button type="button" class="btn user-delete left" zid="{$data['id']}">删除</button>
				<if condition="$data['dh_message'] neq '' and $data['arrive_status'] eq -1">
					<button type="button" class="btn audit2 left ml10" zid="{$data['audit_id']}" uuid="{$login_id}">重新提交审核</button>
				<else/>
					<button type="button" class="btn user-submit left ml10" zid="{$data['audit_id']}" uuid="{$login_id}">提交审核</button>
				</if>
				<button type="button" class="btn user-affirm">确认</button>
			<elseif condition="$data['status'] eq 1"/>
				<button type="button" class="btn cancel-submit left ml10" zid="{$data['audit_id']}">放弃提交</button>
			</if>
		<else/>
			<button type="button" class="btn user-affirm">确认</button>
		</if>
	</if>
	<button type="button" class="btn btn-default user-cancel ml10" data-dismiss="modal">取消</button>
</div>
<script type="text/javascript">
$(function(){
	//删除
	$(".user-delete").click(function(){
		var zid = $(this).attr('zid');
		$('#modal-delete .delete-confirm').attr('zid',zid);
		$('#modal-delete').fadeIn().addClass('opacity');
		$('.mask').fadeIn();
	})
	$("[name='agent1']").select2();
	$("[name='agent2']").select2();
	//代理人选择
	$("[name='agent1']").on('change',function(){
		var val = $(this).val(),
			text = $(this).nextAll(".select-add-text"),
			zname= $(this).find("option:selected").attr('z-name'),
			ttell = $(this).find("option:selected").attr('t-tell');
		if(val==-10){
			text.show();
			$("[name='agent_post1']").val('').show().next('.txt').hide();
			$("[name='agent_tel1']").val('').show().next('.txt').hide();
		}else{
			text.hide().val("").nextAll(".error-item").hide();
			$("[name='agent_post1']").hide().next('.txt').html(zname).show();
			$("[name='agent_tel1']").hide().next('.txt').html(ttell).show();
		}
	});
	$("[name='agent2']").on('change',function(){
		var val = $(this).val(),
			text = $(this).nextAll(".select-add-text"),
			zname= $(this).find("option:selected").attr('z-name'),
			ttell = $(this).find("option:selected").attr('t-tell');
		if(val==-10){
			text.show();
			$("[name='agent_post2']").val('').show().next('.txt').hide();
			$("[name='agent_tel2']").val('').show().next('.txt').hide();
		}else{
			text.hide().val("").nextAll(".error-item").hide();
			$("[name='agent_post2']").hide().next('.txt').html(zname).show();
			$("[name='agent_tel2']").hide().next('.txt').html(ttell).show();
		}
	});
	$("[name='pid'],[name='pid_edit']").change(function(){
		var val = $(this).find("option:selected").val(),
			tdate = $("[name='date']").val(),
			tdate2 = $("[name='start_date']").val(),
			tdate3 = $("[name='end_date']").val(),
			mid = "{$data['id']}";
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":val,"date":tdate,"start":tdate2,"end":tdate3,"mid":mid,"action":"user"},
			url:"__APP__/Index/schedule_list_ajax",
			success:function(data){
				if(data){
					var html="<option value='-10'>请选择</option>";
					for(var d=0;d<data.length;d++){
						html+="<option value='"+data[d].id+"' z-name='"+data[d].position+"' t-tell='"+data[d].mobilephone+"'>"+data[d].username+"</option>";
					}
					$("[name='agent1']").html(html).select2();
					$("[name='agent2']").html(html).select2();
				}else{
					$("[name='agent1']").html("<option value='-10'>暂无相关人员</option>").select2();
					$("[name='agent2']").html("<option value='-10'>暂无相关人员</option>").select2();
				}
			}
		})
		$("[name='agent_name1']").val('').show();
		$("[name='agent_name2']").val('').show();
		$("[name='agent_post1']").val('').show().next('.txt').hide();
		$("[name='agent_tel1']").val('').show().next('.txt').hide();
		$("[name='agent_tel2']").val('').show().next('.txt').hide();
		$("[name='agent_post2']").val('').show().next('.txt').hide();
	})
	//提交
	$('.user-affirm').click(function(){
		var tag = true,
			mid = "{$data['id']}";
		if(mid){
			if($("[name='agent2']").val()==-10){
				if($("[name='agent_name2']").val()==''){
					$("[name='agent_name2']").nextAll('.error-item').show();
					tag = false;
				}
				if($("[name='agent_post2']").val()==''){
					$("[name='agent_post2']").nextAll('.error-item').show();
					tag = false;
				}
				if($("[name='agent_tel2']").val()==''){
					$("[name='agent_tel2']").nextAll('.error-item').show();
					tag = false;
				}
			}
			if($("[name='pid_edit']").val()==-10){
				$("[name='pid_edit']").nextAll('.error-item').show();
				tag = false;
			}
			if($("[name='fill_edit']").val()==-10){
				$("[name='fill_edit']").nextAll('.error-item').show();
				tag = false;
			}
		}else{
			if($("[name='agent1']").val()==-10){
				if($("[name='agent_name1']").val()==''){
					$("[name='agent_name1']").nextAll('.error-item').show();
					tag = false;
				}
				if($("[name='agent_post1']").val()==''){
					$("[name='agent_post1']").nextAll('.error-item').show();
					tag = false;
				}
				if($("[name='agent_tel1']").val()==''){
					$("[name='agent_tel1']").nextAll('.error-item').show();
					tag = false;
				}
			}
			if($("[name='pid']").val()==-10){
				$("[name='pid']").nextAll('.error-item').show();
				tag = false;
			}
			if($("[name='fill_post']").val()==-10){
				$("[name='fill_post']").nextAll('.error-item').show();
				tag = false;
			}
		}
		if(tag){
			var tdate = $("[name='date']").val(),
				tdate2 = $("[name='start_date']").val(),
				tdate3 = $("[name='end_date']").val(),
				ttype = $('.schedule_btn .active').attr('type'),
				pid = $("[name='pid']").find('option:selected').val(),
				fill = $("[name='fill_post']").find('option:selected').val(),
				pid2 = $("[name='pid_edit']").find('option:selected').val(),
				fill2 = $("[name='fill_edit']").find('option:selected').val();
			if(mid){
				var agent = $("[name='agent2']").val(),
					agent_name = $("[name='agent_name2']").val(),
					agent_post = $("[name='agent_post2']").val(),
					agent_tel = $("[name='agent_tel2']").val();
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"agent":agent,"agent_name":agent_name,"agent_post":agent_post,"agent_tel":agent_tel,"ttype":ttype,"pid":pid2,"fill":fill2,"id":mid},
					url:"__APP__/Index/schedule_list_doedit",
					success:function(data){
						$('#edit_modal').hide();
						success_pop(data.status,data.msg);
					}
				});
			}else{
				var agent = $("[name='agent1']").val(),
					agent_name = $("[name='agent_name1']").val(),
					agent_post = $("[name='agent_post1']").val(),
					agent_tel = $("[name='agent_tel1']").val();
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"agent":agent,"agent_name":agent_name,"agent_post":agent_post,"agent_tel":agent_tel,"tdate":tdate,"tdate2":tdate2,"tdate3":tdate3,"ttype":ttype,"pid":pid,"fill":fill},
					url:"__APP__/Index/schedule_list_doadd",
					success:function(data){
						$('#date_modal').hide();
						success_pop(data.status,data.msg);
					}
				});
			}
		}
	})
	//提交、取消提交
	$('.user-submit').click(function(){
		var status = 1,
			uuid = $(this).attr("uuid"),
			state = 1,
			mid = $(this).attr("zid");
		$.ajax({
			cache:true,
			type:"POST",
			dataType:"json",
			data:{"mid":mid,"status":status,"uuid":uuid,"state":state},
			url:"__APP__/Index/schedule_list_audit_ajax",
			success:function(data){
				$('#edit_modal').hide();
				success_pop(data.status,data.msg);
			}
		});
	})
	$('.cancel-submit').click(function(){
		var status = -1,
			state = 1,
			mid = $(this).attr("zid");
		$.ajax({
			cache:true,
			type:"POST",
			dataType:"json",
			data:{"mid":mid,"status":status,"state":state},
			url:"__APP__/Index/schedule_list_audit_ajax",
			success:function(data){
				$('#edit_modal').hide();
				success_pop(data.status,data.msg);
			}
		});
	})
	//取消提示
	$("[name='agent1'],[name='agent2']").change(function(){
		$(this).parents('.load_box').find('.error-item').hide();
	})
	$("[name='agent_name1'],[name='agent_name2'],[name='agent_post1'],[name='agent_tel1'],[name='agent_post2'],[name='agent_tel2']").focus(function(){
		$(this).nextAll('.error-item').hide();
	})
	
	/*重新提交*/
	$(".audit2").click(function(){
		var zid = $(this).attr("zid"),
			uuid = $(this).attr("uuid");

		$("#myModal_submit .btn-affirm").attr("zid",zid);
		$("#myModal_submit .btn-affirm").attr("uuid",uuid);
		$(".submit_info").removeClass("red").val("");
		$('#myModal_submit').modal('toggle');
	});
	
	$("#myModal_submit .btn-affirm").click(function(){
		var zid = $(this).attr("zid"),
			uuid = $(this).attr("uuid"),
			status = 1,
			state = 1,
			submit_info = $(".submit_info").val();

		if(submit_info==""||submit_info=="重新提交理由必填"){
			$(".submit_info").addClass("red").val("重新提交理由必填");
		}else{
			$('#myModal_submit').hide();
			$.ajax({
				cache:true,
				type:"POST",
				dataType:"json",
				global: false,
				url:"__APP__/Index/schedule_list_audit_ajax",
				data:{"mid":zid,"status":status,"uuid":uuid,"state":state,"submit_info":submit_info},
				success:function(data){
					success_pop(data['status'],data['msg']);
				}
			});
		}
	});

	$(".submit_info").focus(function(){
		if($(this).val()=="重新提交理由必填"){
			$(this).removeClass("red").val("");
		}
	});
});
</script>
</body>
</html>
